<?php

namespace app\logic\model\music;

use app\logic\model\LogicModel;
use app\logic\model\user\UserLogicModel;
use think\model\concern\SoftDelete;

class MusicCommentLogicModel extends LogicModel
{
    use SoftDelete;
    protected $name='music_comment';


    public function user(){
        return $this->hasOne(UserLogicModel::class,'id','user_id');
    }
    function create_comment($user_id,$goods_id,$type,$content){
        $this->save([
            'user_id'=>$user_id,
            'goods_id'=>$goods_id,
            'type'=>$type,
            'content'=>$content
        ]);
    }
    public function getList(\think\Request $request, array $where, string $field='*', $page = 1, $limit=15,$order='id desc')
    {
        $query=$this->where($where)
            ->where(function ($q) use ($request){
                if(check_request($request,'title')){
                    $q->whereLike("title","%{$request['title']}%");
                }
                if(check_request($request,'goods_id')){
                    $q->where("goods_id",$request['goods_id']);
                }
                if(check_request($request,'type')){
                    $q->where("type",$request['type']);
                }
            });
        $list = $query->field($field)->order($order)
            ->with(['user'])
            ->page($page,$limit)->select();
        $count = $query->count();
        return [$list,$count];
    }
}